home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 25 / AMIGAplus Sonderheft 25 (2000)(Falke)(DE)(Track 1 of 4)[!].iso / PublicDomain / Anwendungen / AmigaEYE_V39.7 / ScreenNotifly.lha / ScreenNotify / src / screennotify.c < prev    next >
C/C++ Source or Header  |  1995-03-26  |  6KB  |  189 lines

  1. /*
  2.  * screennotify.c V1.0
  3.  *
  4.  * Library routines
  5.  *
  6.  * (c) 1995 Stefan Becker
  7.  */
  8.  
  9. #include "screennotify.h"
  10.  
  11. /*
  12.  * Object file dummy entry point
  13.  */
  14. static ULONG Dummy(void)
  15. {
  16.  return(-1);
  17. }
  18.  
  19. /* Library name and ID string */
  20. static const char LibraryName[] = SCREENNOTIFY_NAME;
  21. static const char LibraryID[]   = "$VER: " SCREENNOTIFY_NAME " "
  22.                                   INTTOSTR(SCREENNOTIFY_VERSION) "."
  23.                                   INTTOSTR(SCREENNOTIFY_REVISION) " ("
  24.                                   __COMMODORE_DATE__ ")\r\n";
  25.  
  26. /* Standard library function prototypes */
  27. __geta4 static struct Library *LibraryInit(__A0 BPTR, __A6 struct Library *);
  28. __geta4 static struct Library *LibraryOpen(__A6 struct ScreenNotifyBase *);
  29. __geta4 static BPTR            LibraryClose(__A6 struct Library *);
  30. __geta4 static BPTR            LibraryExpunge(__A6 struct ScreenNotifyBase *);
  31.         static ULONG           LibraryReserved(void);
  32.  
  33. /* ROMTag structure */
  34. static const struct Resident ROMTag = { RTC_MATCHWORD, &ROMTag, &ROMTag + 1, 0,
  35.  SCREENNOTIFY_VERSION, NT_LIBRARY, 0, LibraryName, LibraryID, LibraryInit
  36. };
  37.  
  38. /* Library functions table */
  39. static const APTR LibraryVectors[] = {
  40.  /* Standard functions */
  41.  (APTR) LibraryOpen,
  42.  (APTR) LibraryClose,
  43.  (APTR) LibraryExpunge,
  44.  (APTR) LibraryReserved,
  45.  
  46.  /* Library specific functions */
  47.  (APTR) _AddCloseScreenClient,
  48.  (APTR) _RemCloseScreenClient,
  49.  (APTR) _AddPubScreenClient,
  50.  (APTR) _RemPubScreenClient,
  51.  (APTR) _AddWorkbenchClient,
  52.  (APTR) _RemWorkbenchClient,
  53.  
  54.  /* End of table */
  55.  (APTR) -1
  56. };
  57.  
  58. /* Library bases */
  59. struct Library          *SysBase          = NULL;
  60. struct ScreenNotifyBase *ScreenNotifyBase = NULL;
  61.  
  62. /* Initialize client list data */
  63. static void InitClientListData(struct ClientListData *cld)
  64. {
  65.  /* Initialize client list */
  66.  NewList(&cld->cld_List);
  67.  
  68.  /* Initialize semaphore */
  69.  InitSemaphore(&cld->cld_Semaphore);
  70.  
  71.  /* Initialize message */
  72.  cld->cld_Message.snm_Message.mn_ReplyPort = &cld->cld_MsgPort;;
  73.  cld->cld_Message.snm_Message.mn_Length    = sizeof(struct ScreenNotifyMessage);
  74.  
  75.  /* Initialize message port */
  76.  NewList(&cld->cld_MsgPort.mp_MsgList);
  77.  cld->cld_MsgPort.mp_Node.ln_Type = NT_MSGPORT;
  78.  cld->cld_MsgPort.mp_Flags        = PA_SIGNAL;
  79. }
  80.  
  81. /* Initialize library */
  82. __geta4 static struct Library *LibraryInit(__A0 BPTR Segment,
  83.                                            __A6 struct Library *ExecBase)
  84. {
  85.  /* Initialize SysBase */
  86.  SysBase = ExecBase;
  87.  
  88.  if (ScreenNotifyBase = (struct ScreenNotifyBase *) MakeLibrary(LibraryVectors,
  89.                                                                 NULL, NULL,
  90.                                                        sizeof(struct ScreenNotifyBase),
  91.                                                                 NULL)) {
  92.   /* Initialize libray structure */
  93.   ScreenNotifyBase->snb_Library.lib_Node.ln_Type = NT_LIBRARY;
  94.   ScreenNotifyBase->snb_Library.lib_Node.ln_Name = LibraryName;
  95.   ScreenNotifyBase->snb_Library.lib_Flags        = LIBF_CHANGED | LIBF_SUMUSED;
  96.   ScreenNotifyBase->snb_Library.lib_Version      = SCREENNOTIFY_VERSION;
  97.   ScreenNotifyBase->snb_Library.lib_Revision     = SCREENNOTIFY_REVISION;
  98.   ScreenNotifyBase->snb_Library.lib_IdString     = (APTR) LibraryID;
  99.   ScreenNotifyBase->snb_Segment                  = Segment;
  100.   ScreenNotifyBase->snb_IntuitionBase            = NULL;
  101.   InitClientListData(&ScreenNotifyBase->snb_CloseScreenClients);
  102.   InitClientListData(&ScreenNotifyBase->snb_PubScreenClients);
  103.   InitClientListData(&ScreenNotifyBase->snb_WorkbenchClients);
  104.  
  105.   /* Add the library to the system */
  106.   AddLibrary((struct Library *) ScreenNotifyBase);
  107.  }
  108.  
  109.  /* Return new library pointer */
  110.  return(ScreenNotifyBase);
  111. }
  112.  
  113. /* Standard library function: Open. Called in Forbid() state */
  114. __geta4 static struct Library *LibraryOpen(__A6 struct ScreenNotifyBase *snb)
  115. {
  116.  /* Oh another user :-) */
  117.  snb->snb_Library.lib_OpenCnt++;
  118.  
  119.  /* Reset delayed expunge flag */
  120.  snb->snb_Library.lib_Flags &= ~LIBF_DELEXP;
  121.  
  122.  /* Check if patches have to be applied */
  123.  if ((snb->snb_IntuitionBase == NULL) &&
  124.      (snb->snb_IntuitionBase = OpenLibrary("intuition.library", 37)))
  125.  
  126.   /* Install patches */
  127.   PatchFunctions(snb->snb_IntuitionBase);
  128.  
  129.  /* Return library pointer */
  130.  return(snb);
  131. }
  132.  
  133. /* Standard library function: Close. Called in Forbid() state */
  134. __geta4 static BPTR LibraryClose(__A6 struct Library *lib)
  135. {
  136.  BPTR rc = NULL;
  137.  
  138.  /* Open count greater zero, only one user and delayed expunge bit set? */
  139.  if ((lib->lib_OpenCnt > 0) && (--lib->lib_OpenCnt == 0) &&
  140.      (lib->lib_Flags & LIBF_DELEXP))
  141.  
  142.   /* Yes, try to remove the library */
  143.   rc = LibraryExpunge((struct ScreenNotifyBase *) lib);
  144.  
  145.  DEBUGLOG(kprintf("Close result: %08lx\n", rc);)
  146.  
  147.  /* Return library segment if remove successful */
  148.  return(rc);
  149. }
  150.  
  151. /* Standard library function: Expunge. Called in Forbid() state */
  152. __geta4 static BPTR LibraryExpunge(__A6 struct ScreenNotifyBase *snb)
  153. {
  154.  BPTR rc = NULL;
  155.  
  156.  /* Does no-one use library now? */
  157.  if (snb->snb_Library.lib_OpenCnt > 0) {
  158.   /* No, library still in use -> set delayed expunge flag */
  159.   snb->snb_Library.lib_Flags |= LIBF_DELEXP;
  160.  
  161.  /* Patches applied and can they be removed? */
  162.  } else if ((snb->snb_IntuitionBase == NULL) ||
  163.             RemoveFunctionPatches(snb->snb_IntuitionBase)) {
  164.   /* Yes, remove library */
  165.   Remove(&snb->snb_Library.lib_Node);
  166.  
  167.   /* Close intuition.library if needed */
  168.   if (snb->snb_IntuitionBase) CloseLibrary(snb->snb_IntuitionBase);
  169.  
  170.   /* Return library segment */
  171.   rc = snb->snb_Segment;
  172.  
  173.   /* Free memory for library base */
  174.   FreeMem((void *) ((ULONG) snb - snb->snb_Library.lib_NegSize),
  175.           snb->snb_Library.lib_NegSize + snb->snb_Library.lib_PosSize);
  176.  }
  177.  
  178.  DEBUGLOG(kprintf("Expunge result: %08lx\n", rc);)
  179.  
  180.  /* Return library segment if remove successful */
  181.  return(rc);
  182. }
  183.  
  184. /* Reserved function, returns NULL */
  185. static ULONG LibraryReserved(void)
  186. {
  187.  return(NULL);
  188. }
  189.